home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / toda / src / movplay.c < prev    next >
Text File  |  1991-10-18  |  24KB  |  974 lines

  1. /*            VIDEO PLAY
  2.  
  3.             Hiroshi TODA
  4.             1991 2/11
  5.  
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <egb.h>
  11. #include <mos.h>
  12. #include <snd.h>
  13. #include "video.h"
  14.  
  15. #define C_WT 0x7fff        /* カーソル color */
  16. #define C_PL 24311        /* 初期プレーン color */
  17. #define C_FL 0x303030        /* files back color */
  18. #define C_COLOR 15        /* Command color palette */
  19. #define W_COLOR 8        /* Window color palette */
  20. #define B_COLOR 7        /* Back color palette */
  21. #define E_COLOR 10        /* ERROR color palette */
  22. #define P_COLOR 12        /* PLAY color palette */
  23.  
  24. int sw = 0, cx = 0, cy = 0;    /* MOUSE data */
  25.  
  26. char para[256];        /* PARAM */
  27. char gwork[1024];    /* 自家製 graphic work */
  28. char swork[16384];    /* SND work */
  29. char ework[1536];    /* EGB work */
  30. char mwork[4096];    /* MOUSE work */
  31.  
  32. void display_ini()
  33. {
  34.     DWORD(para+0) = 0x1b80;            /* console ini */
  35.     console(gwork,para);
  36.     EGB_init(ework,1536);            /* graph ini */
  37.     EGB_resolution(ework,0,10);        /* モード10,3合成 */
  38.     EGB_resolution(ework,1,3);
  39.     EGB_writePage(ework,0);            /* mode10設定 */
  40.     EGB_displayStart(ework,2,2,2);
  41.     EGB_displayStart(ework,3,320,240);
  42.     EGB_color(ework,0,C_PL);        /* clear paint */
  43.     EGB_color(ework,2,C_PL);
  44.     EGB_paintMode(ework,0x22);
  45.     EGB_writeMode(ework,0);
  46.     EGB_penSize(ework,1);
  47.     WORD(para+0) = 0;
  48.     WORD(para+2) = 0;
  49.     WORD(para+4) = 319;
  50.     WORD(para+6) = 239;
  51.     EGB_rectangle(ework,para);
  52.     EGB_writePage(ework,1);            /* mode3に書き込み */
  53.     EGB_displayPage(ework,1,3);        /* mode3が前側 */
  54.     MOS_start(mwork,4096);            /* mouse ini */
  55.     MOS_resolution(0,10);
  56.     MOS_resolution(1,3);
  57.     MOS_writePage(1);
  58.     MOS_horizon(0,639);
  59.     MOS_vertical(0,479);
  60.     MOS_disp(0);
  61.     MOS_setpos( 320, 240 );
  62.     DWORD(para+0) = 0;            /* key ini */
  63.     keyin(gwork,para);
  64.     DWORD(para+0) = 0x0200;            /* ASCII code */
  65.     DWORD(para+4) = 0;
  66.     DWORD(para+8) = 0;
  67.     DWORD(para+12) = 0;
  68.     keyin(gwork,para);
  69.     DWORD(para+0) = 1;            /* files背景色 */
  70.     DWORD(para+4) = 7;
  71.     DWORD(para+8) = C_FL;
  72.     EGB_palette(ework,1,para);
  73. }
  74.  
  75. void ini()
  76. {
  77.     SND_init(swork);
  78.     SND_elevol_init();
  79.     SND_elevol_mute(0x03);
  80.     display_ini();
  81. }
  82.  
  83. void end()
  84. {
  85.     MOS_end();
  86.     EGB_init(ework,1536);
  87.     DWORD(para+0) = 0;
  88.     SND_elevol_mute(0);
  89.     SND_end();
  90.     keyin(gwork,para);
  91. }
  92.  
  93. windget()
  94. {
  95.     EGB_writePage(ework,1);        /* mode3に書き込み */
  96.     EGB_clearScreen(ework);
  97.     EGB_textZoom(ework,0,8,16);
  98.     EGB_textZoom(ework,1,16,16);
  99.     EGB_writeMode(ework,0);
  100.     EGB_color(ework,0,W_COLOR);    /* Window paint */
  101.     EGB_color(ework,2,W_COLOR);
  102.     EGB_paintMode(ework,0x22);
  103.     EGB_writeMode(ework,0);
  104.     WORD(para+0) = 0;
  105.     WORD(para+2) = 448;
  106.     WORD(para+4) = 639;
  107.     WORD(para+6) = 479;
  108.     EGB_rectangle(ework,para);
  109.     EGB_color(ework,0,C_COLOR);
  110.     EGB_displayPage(ework,1,3);        /* mode3が前側 */
  111.     return 0;
  112. }
  113.  
  114. windput()
  115. {
  116.     EGB_clearScreen(ework);
  117.     EGB_displayPage(ework,1,1);        /* mode10のみ表示 */
  118.     return 0;
  119. }
  120.  
  121. mouse(mmd)
  122. int mmd;
  123. {
  124.     int s, x, y;
  125.  
  126.     do{
  127.         MOS_rdpos(&sw,&cx,&cy);
  128.     }while( sw == 0 );
  129.     if( mmd == 0 ){
  130.         do{
  131.             MOS_rdpos(&s,&x,&y);
  132.         }while( s );
  133.     }
  134.     return 0;
  135. }
  136.  
  137. itochar(n,count,p)    /* n --> char p[count] */
  138. int n,count;
  139. char *p;
  140. {
  141.     char dsp[] = "0123456789ABCDEF";
  142.  
  143.     switch( count ){
  144.         case 8: *p++ = dsp[ n/10000000 ];
  145.             n = n % 10000000;
  146.         case 7: *p++ = dsp[ n/1000000 ];
  147.             n = n % 1000000;
  148.         case 6: *p++ = dsp[ n/100000 ];
  149.             n = n % 100000;
  150.         case 5: *p++ = dsp[ n/10000 ];
  151.             n = n % 10000;
  152.         case 4: *p++ = dsp[ n/1000 ];
  153.             n = n % 1000;
  154.         case 3: *p++ = dsp[ n/100 ];
  155.             n = n % 100;
  156.         case 2: *p++ = dsp[ n/10 ];
  157.             n = n % 10;
  158.         case 1: *p++ = dsp[ n ];
  159.             *p = (char)0;
  160.     }
  161.     return 0;
  162. }
  163.  
  164. ginput( p, x, y, max )        /* キーボード入力 */
  165. char *p;
  166. int x,y,max;
  167. {
  168.     int i,a;
  169.  
  170.     MOS_disp(0);
  171.     EGB_paintMode(ework,0x22);
  172.     EGB_writeMode(ework,0);
  173.     EGB_color(ework,0,C_COLOR);
  174.     BYTE( p + max ) = 0;
  175.  
  176. gin01:    for ( i=0 ; i<=max ; i++ ){
  177.         if( BYTE( p + i ) == 0 )break;
  178.     }
  179.     gprint( p, x, y );
  180.  
  181.     EGB_color(ework,0,W_COLOR);        /* 2 Brock del */
  182.     EGB_color(ework,2,W_COLOR);
  183.     WORD(para+0) = x + i*8;
  184.     WORD(para+2) = y - 15;
  185.     WORD(para+4) = x + i*8 + 15;
  186.     WORD(para+6) = y;
  187.     EGB_rectangle(ework,para);
  188.     EGB_color(ework,0,C_COLOR);
  189.  
  190.     gprint( "_", x+i*8, y+1 );
  191. gin02:    a = keyinput();
  192.     if( a == -1 )return 0;
  193.     if( (a == 0x08) && (i > 0) ){
  194.         BYTE( p + i -1 ) = 0;
  195.         goto gin01;
  196.     }
  197.     if( a == 0x0d )return 0;
  198.     if( (a < 0x20) || (a == 0x7f) )goto gin02;
  199.     if( i < max ){
  200.         WORD( p + i ) = a;
  201.         EGB_color(ework,0,W_COLOR);
  202.         gprint( "_", x+i*8, y+1 );
  203.         EGB_color(ework,0,C_COLOR);
  204.     }
  205.     goto gin01;
  206. }
  207.  
  208. keyinput()        /* 1文字input */
  209. {
  210.     char p[32], q[32];
  211.  
  212.     MOS_disp(1);
  213.     DWORD(p+0) = 0x0901;
  214.     do{
  215.         keyin(q,p);
  216.         MOS_rdpos(&sw,&cx,&cy);    /* mouse sw1 -> back */
  217.         if( sw & 1 )return -1;
  218.     }while( BYTE(q + 13) == 0xff );    /* DH = 0xff->(no input) */
  219.     MOS_disp(0);
  220.     return BYTE(q + 12);        /* DL = key input */
  221. }
  222.  
  223. gprint( p, x, y )    /* LINE PRINT */
  224. char *p;
  225. int x,y;
  226. {
  227.     int i;
  228.     char dsp[86];
  229.  
  230.     EGB_writePage(ework,1);            /* mode3に書き込み */
  231.     WORD(dsp+0) = x;
  232.     WORD(dsp+2) = y;
  233.     for ( i=0 ; i<80 ; i++ ){
  234.         dsp[ i + 6 ] = (char)( BYTE( p + i ) );
  235.         if( dsp[ i + 6 ] == (char)0 )break;
  236.     }
  237.     WORD(dsp+4) = i;
  238.     EGB_writeMode(ework,0);
  239.     EGB_sjisString(ework,dsp);
  240.     return 0;
  241. }
  242.  
  243. gprint2( p, x, y )    /* LINE PRINT ( OVER WRITE ) */
  244. char *p;
  245. int x,y;
  246. {
  247.     int i;
  248.     char dsp[70];
  249.  
  250.     EGB_writePage(ework,1);            /* mode3に書き込み */
  251.     for ( i=0 ; i<64 ; i++ ){
  252.         dsp[ i + 6 ] = (char)( BYTE( p + i ) );
  253.         if( dsp[ i + 6 ] == (char)0 )break;
  254.     }
  255.     EGB_paintMode(ework,0x22);
  256.     EGB_writeMode(ework,0);
  257.     EGB_color(ework,0,W_COLOR);        /* Brock del */
  258.     EGB_color(ework,2,W_COLOR);
  259.     WORD(para+0) = x;
  260.     WORD(para+2) = y - 15;
  261.     WORD(para+4) = x + i*8;
  262.     WORD(para+6) = y;
  263.     EGB_rectangle(ework,para);
  264.     EGB_color(ework,0,C_COLOR);
  265.     WORD(dsp+0) = x;
  266.     WORD(dsp+2) = y;
  267.     WORD(dsp+4) = i;
  268.     EGB_sjisString(ework,dsp);
  269.     return 0;
  270. }
  271.  
  272. /* file display */
  273.  
  274. look_files( path, fullname )
  275. char path[65], fullname[80];
  276. {
  277.     int i,j,k,n,m;
  278.     char out[64], dta[64], name[48][14];
  279.     int point[][2] = {
  280.                 {   8, 76 },
  281.                 { 232, 76 },
  282.                 { 456, 76 },
  283.  
  284.                 {   8,100 },
  285.                 { 232,100 },
  286.                 { 456,100 },
  287.  
  288.                 {   8,124 },
  289.                 { 232,124 },
  290.                 { 456,124 },
  291.  
  292.                 {   8,148 },
  293.                 { 232,148 },
  294.                 { 456,148 },
  295.  
  296.                 {   8,172 },
  297.                 { 232,172 },
  298.                 { 456,172 },
  299.  
  300.                 {   8,196 },
  301.                 { 232,196 },
  302.                 { 456,196 },
  303.  
  304.                 {   8,220 },
  305.                 { 232,220 },
  306.                 { 456,220 },
  307.  
  308.                 {   8,244 },
  309.                 { 232,244 },
  310.                 { 456,244 },
  311.  
  312.                 {   8,268 },
  313.                 { 232,268 },
  314.                 { 456,268 },
  315.  
  316.                 {   8,292 },
  317.                 { 232,292 },
  318.                 { 456,292 },
  319.  
  320.                 {   8,316 },
  321.                 { 232,316 },
  322.                 { 456,316 },
  323.  
  324.                 {   8,340 },
  325.                 { 232,340 },
  326.                 { 456,340 },
  327.  
  328.                 {   8,364 },
  329.                 { 232,364 },
  330.                 { 456,364 },
  331.  
  332.                 {   8,388 },
  333.                 { 232,388 },
  334.                 { 456,388 },
  335.  
  336.                 {   8,412 },
  337.                 { 232,412 },
  338.                 { 456,412 },
  339.  
  340.                 {   8,436 },
  341.                 { 232,436 },
  342.                 { 456,436 }
  343.                };
  344.     char dsp[] = "<<FILES>> NEXT                                                              EXIT";
  345.     char para2[64], para3[64],path2[64];    /* path2保存用 */
  346.  
  347.     windget();
  348.     for( i=0 ; i<64 ; i++ )path2[i] = path[i];    /* 保存 */
  349. file0A:    if( path[0] == (char)0 ){
  350.         path[0] = '\\';
  351.         path[1] = (char)0;
  352.     }
  353.     if( path[0] != (char)0 ){
  354.         k = 0;
  355.         for( i = 0 ; i<59 ; i++ ){
  356.             if( path[i] == (char)0 )break;
  357.             if( (path[i] == '*') || (path[i] == '.') ){
  358.                 k = 1;
  359.                 break;
  360.             }
  361.         }
  362.         if( k )for( i = 0 ; i<64 ; i++ )path[i] = path2[i];
  363.         for( i = 0 ; i<59 ; i++ ){
  364.             para3[i] = path[i];
  365.             if( para3[i] == (char)0 )break;
  366.         }
  367.         if( k == 0 ){
  368.             if( para3[i-1] != '\\' ){
  369.                 path[i] = '\\';
  370.                 path[i+1] = (char)0;
  371.                 para3[i++] = '\\';
  372.             }
  373.             para3[i++] = '*';
  374.             para3[i++] = '.';
  375.             para3[i++] = '*';
  376.             para3[i++] = (char)0;
  377.         }
  378.     }
  379.     EGB_color(ework,0,B_COLOR);
  380.     EGB_color(ework,2,B_COLOR);
  381.     EGB_paintMode(ework,0x22);
  382.     EGB_writeMode(ework,0);
  383.     WORD(para+0) = 0;
  384.     WORD(para+2) = 0;
  385.     WORD(para+4) = 639;
  386.     WORD(para+6) = 479;
  387.     EGB_rectangle(ework,para);
  388.     EGB_color(ework,0,W_COLOR);
  389.     EGB_color(ework,2,W_COLOR);
  390.     EGB_paintMode(ework,0x22);
  391.     EGB_writeMode(ework,0);
  392.     WORD(para+0) = 0;
  393.     WORD(para+2) = 0;
  394.     WORD(para+4) = 639;
  395.     WORD(para+6) = 47;
  396.     EGB_rectangle(ework,para);
  397.     WORD(para+0) = 0;
  398.     WORD(para+2) = 448;
  399.     WORD(para+4) = 639;
  400.     WORD(para+6) = 479;
  401.     EGB_rectangle(ework,para);
  402.     EGB_color(ework,0,C_COLOR);
  403.     gprint( dsp, 0, 463 );
  404. file00:    n = 0;
  405.     DWORD(para2+0) = ( unsigned int )para3;
  406.     DWORD(para2+4) = ( unsigned int )out;
  407.     DWORD(para2+8) = ( unsigned int )dta;
  408.     DWORD(para2+12) = 0x30;
  409.     DWORD(para2+16) = 0;
  410.     k = files( gwork, para2 );
  411.     if( k != 0 ){
  412.         gprint( "File Not found", 8, 32 );
  413.         goto file03;
  414.     }
  415.     gprint( "<<PATH NAME>>", 8, 32 );        /* path name disp */
  416.     gprint( path, 120, 32 );
  417.     gprint( out, point[0][0], point[0][1] );    /* first disp */
  418.     itochar( DWORD( dta + 0x1a ), 8, out + 16 );
  419.     if( dta[0x15] != 0x10 ){            /* file name */
  420.         gprint( out + 16, point[0][0] + 112, point[0][1] );
  421.     }
  422.     if( dta[0x15] == 0x10 ){            /* dir */
  423.         gprint( " <<DIR>>", point[0][0] + 112, point[0][1] );
  424.     }
  425.     for( i=0 ; i<13 ; i++ )name[0][i] = dta[ i + 0x1e ];    /* f-name */
  426.     name[0][13] = dta[ 0x15 ];                /* attr. */
  427.     n++;
  428. file01:    DWORD(para2+0) = ( unsigned int )para3;
  429.     DWORD(para2+4) = ( unsigned int )out;
  430.     DWORD(para2+8) = ( unsigned int )dta;
  431.     DWORD(para2+12) = 0x30;
  432.     DWORD(para2+16) = 1;
  433.     k = files( gwork, para2 );
  434.     if( k != 0 )goto file02;
  435.     gprint( out, point[n][0], point[n][1] );
  436.     itochar( DWORD( dta + 0x1a ), 8, out + 16 );
  437.     if( dta[0x15] != 0x10 ){            /* file name */
  438.         gprint( out + 16, point[n][0] + 112, point[n][1] );
  439.     }
  440.     if( dta[0x15] == 0x10 ){            /* dir */
  441.         gprint( " <<DIR>>", point[n][0] + 112, point[n][1] );
  442.     }
  443.     for( i=0 ; i<13 ; i++ )name[n][i] = dta[ i + 0x1e ];    /* f-name */
  444.     name[n][13] = dta[ 0x15 ];                /* attr. */
  445.     n++;
  446.     if( n < 48 )goto file01;
  447. file02:    if( n == 0 )goto file0A;
  448. file03:    MOS_disp(1);                /* command */
  449.     do{ mouse(0); }while( sw & 2 ); /* sw=2 は決定の意思なし */
  450.     MOS_disp(0);
  451.     if( (cy > 447) && (cy < 463) ){
  452.         if( cx < 72 )goto file02;
  453.         if( cx < 120 ){            /* next */
  454.             EGB_color(ework,0,B_COLOR);
  455.             EGB_color(ework,2,B_COLOR);
  456.             EGB_paintMode(ework,0x22);
  457.             EGB_writeMode(ework,0);
  458.             WORD(para+0) = 0;
  459.             WORD(para+2) = 48;
  460.             WORD(para+4) = 639;
  461.             WORD(para+6) = 447;
  462.             EGB_rectangle(ework,para);
  463.             EGB_color(ework,0,C_COLOR);
  464.             n = 0;
  465.             if( k == 0 )goto file01;
  466.             if( k != 0 )goto file00;
  467.         }
  468.         if( cx < 600 )goto file02;    /* nothing */
  469.         if( cx < 640 ){            /* exit */
  470.             for( i=0 ; i<64 ; i++ ){
  471.                 fullname[i] = path[i];
  472.                 if( (path[i]==(char)0)||(path[i]=='*') )break;
  473.             }
  474.             fullname[i] = (char)0;
  475.             EGB_clearScreen(ework);
  476.             return 1;
  477.         }
  478.     }
  479.     for( i = 0 ; i < n ; i++ ){
  480.         if( (cx>point[i][0])
  481.          && (cx<point[i][0]+176)
  482.          && (cy>point[i][1]-16)
  483.          && (cy<point[i][1])
  484.         )break;
  485.     }
  486.     if( i >= n )goto file02;        /* nothing */
  487.     if( name[i][13] == (char)(0x10) ){        /* path name */
  488.         if( WORD( *(name + i) ) == 0x2e )goto file02;    /* '.' */
  489.         if( WORD( *(name + i) ) == 0x2e2e ){        /* '..' */
  490.             for( j=0 ; j<59 ; j++ ){    /* 0 search */
  491.                 if( path[j] == (char)0 )break;
  492.             }
  493.             if( (j>=59) || (j < 2) )goto file02;    /* too long */
  494.             j = j - 2;
  495.             for( m=j ; m>=0 ; m-- ){
  496.                 if( path[m] == '\\' )break;
  497.             }
  498.             if( m < 0 )goto file02;
  499.             path[m] = (char)0;
  500.             goto file0A;
  501.         }
  502.         for( j=0 ; j<59 ; j++ ){
  503.             if( path[j] == (char)0 )break;
  504.         }
  505.         if( j>=59 )goto file02;
  506.         for( m=0 ; m<13 ; m++ ){
  507.             if( j >= 59 )break;
  508.             path[ j++ ] = name[i][m];
  509.             if( name[i][m] == (char)0 )break;
  510.         }
  511.         goto file0A;
  512.     }
  513.     for( j=0 ; j<64 ; j++ ){    /* fullname=path+fname */
  514.         fullname[j] = path[j];
  515.         if( (path[j] == (char)0) || (path[j] == '*') )break;
  516.     }
  517.     for( m=0 ; m<13 ; m++ ){
  518.         fullname[j++] = name[i][m];
  519.         if( name[i][m] == (char)0 )break;
  520.     }
  521.     EGB_clearScreen(ework);
  522.     return 0;
  523. }
  524.  
  525. /* file selector */
  526.  
  527. filename( path, fullname )
  528. char path[65], fullname[80];
  529. {
  530.     int i;
  531.     char dsp[] = "<<FILES>>         DRIVER ( A B C D E F G H I J K L M N O P Q )";
  532.  
  533.     windget();
  534.     gprint( dsp, 0, 463 );
  535.     gprint( "Input PATH NAME ? ", 0, 479 );
  536.     gprint( path, 144, 479 );
  537.     MOS_disp(1);
  538.     sw = 0;
  539.     ginput( path, 144, 479, 44 );
  540.     if( (sw & 1) && (cy>447) && (cy<463) && (cx>208) && (cx<488) ){
  541.         mouse(0);
  542.         for( i=0 ; i<17 ; i++ ){
  543.             if( cx < 228 + 16*i ){
  544.                 path[0] = (char)( 'A' + i );
  545.                 path[1] = ':';
  546.                 path[2] = (char)0;
  547.                 break;
  548.             }
  549.         }
  550.     }
  551.     if( path[0] == (char)0 ){
  552.         path[0] = '\\';
  553.         get_directory( 0, path+1 );
  554.     }
  555.     MOS_disp(0);
  556.     return look_files( path, fullname );
  557. }
  558.  
  559. fileinput( fullname )
  560. char fullname[80];
  561. {
  562.     windget();
  563.     gprint( "<<FILE-NAME>>", 0, 463 );
  564.     gprint( "Input FILE NAME ? ", 0, 479 );
  565.     ginput( fullname, 144, 479, 44 );
  566.     windput();
  567.     return 0;
  568. }
  569.  
  570. moving( namemov, wait, md )
  571. char *namemov;
  572. int wait, md;
  573. {
  574.     FILE *fpl;        /* FILE */
  575.     FILE *fps;
  576.     int i, j, n, temp, pcmsw, address, page, total, mode;
  577.     int rep[9][3], replv;
  578.     char *bp, *pbp[8], *p;
  579.     char path[100], pcmname[13];
  580.     int  pbpsz[8], para[20], para2[5];        /* para & work */
  581.     char bbuf[153600];        /* work area for vram making */
  582.  
  583.     EGB_init(ework,1536);            /* graph ini */
  584.         /* file open */
  585.     if( ( fpl = fopen( namemov, "rb" ) ) == NULL )return 1;
  586.     if( fread( bbuf, 1, 256, fpl ) < 256 )goto mov10;
  587.     if( DWORD( bbuf + 0 ) != 0x32564f4d )goto mov10;
  588.     if( DWORD( bbuf + 4 ) != 16 )goto mov10;
  589.     if( DWORD( bbuf + 16) != 320 )goto mov10;
  590.     if( DWORD( bbuf + 20) != 240 )goto mov10;
  591.     page = DWORD( bbuf + 12 );
  592.     total = DWORD( bbuf + 8 );
  593.     if( (bp = (char *)malloc( total )) == 0 ){
  594.         fclose( fpl );            /* out of memory */
  595.         return 7;
  596.     }
  597.     if( fread( bp, 1, total, fpl ) < total )goto mov09;
  598.         /* graphic init */
  599.     md &= 0x01;
  600.     EGB_resolution(ework,0,10+md);        /* 2画面合成 */
  601.     EGB_resolution(ework,1,10+md);
  602.     EGB_displayPage(ework,0,3);
  603.     EGB_writePage(ework,0);            /* 画面0設定 */
  604.     EGB_displayStart(ework,2,2,2);
  605.     EGB_displayStart(ework,3,320,240);
  606.     EGB_writePage(ework,1);         /* 画面1設定 */
  607.     EGB_displayStart(ework,2,2,2);
  608.     EGB_displayStart(ework,3,320,240);
  609.         /* pcm data load */
  610.     for( i=0 ; i<8 ; i++ ){
  611.         pbp[i] = NULL;
  612.         pbpsz[i] = 0;
  613.         if( bbuf[ 72 + 8*i ] ){
  614.             for( j=0 ; j<8 ; j++ ){
  615.                 pcmname[j] = bbuf[ 72+8*i+j ];
  616.                 if( pcmname[j] == (char)0 )break;
  617.             }
  618.             pcmname[j] = '.';
  619.             DWORD( pcmname+j+1 ) = 'S' + 0x100*'N' + 0x10000*'D';
  620.             make_path_name( path, namemov, pcmname );
  621.             if( ( fps = fopen( path, "rb" ) ) == NULL )goto mov01;
  622.             if( fread( bbuf+256, 1, 32, fps ) < 32 )goto mov00;
  623.             total = DWORD( bbuf + 256 + 12 );
  624.             if( (pbp[i] = (char *)malloc( total+32 )) == NULL ){
  625.                 goto mov00;
  626.             }
  627.             for( j=0 ; j<32 ; j++ ){
  628.                 BYTE( pbp[i]+j ) = BYTE( bbuf+256+j );
  629.             }
  630.             if( fread( pbp[i]+32, 1, total, fps ) < total ){
  631.                 free( pbp );
  632.                 pbp[i] = NULL;
  633.                 goto mov00;
  634.             }
  635.             else pbpsz[i] = total + 32;
  636.         mov00:    fclose( fps );
  637.         mov01:    ;
  638.         }
  639.         else {    /* pcm-nameが 0,length (dword) ならarea確保 */
  640.             pbpsz[i] = DWORD( bbuf+72+8*i+4 );
  641.             if( pbpsz[i] ){
  642.             if( (pbp[i] = (char *)malloc( pbpsz[i] )) == NULL ){
  643.                 pbpsz[i] = 0;
  644.             }
  645.             }
  646.         }
  647.     }
  648.     pcmsw = 0;
  649.     for( i=0 ; i<8 ; i++ )if( pbp[i] )pcmsw = 1;
  650.     if( pcmsw ){
  651.         if( SND_pcm_mode_set( 1 ) ){
  652.             SND_pcm_sound_delete( -1 );
  653.             SND_pcm_mode_set( 1 );
  654.         }
  655.     }
  656.     p = ( (char *)para ) + 16;        /* p = page head dada */
  657.     para[1] = (unsigned int)bbuf;
  658.     para[3] = wait;
  659.     address = (unsigned int)bp; mode = 0x02;
  660.     n = 0; replv = 0;
  661.     for( i=0 ; i<9 ; i++ )rep[i][0] = 0;
  662.         /* main loop */
  663. mov02:    if( n >= page ){
  664.         address = (unsigned int)bp;
  665.         n = 0;
  666.     }
  667.     para[0] = address;
  668.     para[2] = mode;
  669.     address = move32( (char *)para );
  670.     mode = mode ^ 0x03;
  671.     if( BYTE(p+20) ){    /* sound1 */
  672.         SND_key_off( BYTE(p+21) );
  673.         if( BYTE(p+23) )SND_key_on( BYTE(p+21), BYTE(p+22), BYTE(p+23) );
  674.     }
  675.     if( BYTE(p+24) ){    /* sound2 */
  676.         SND_key_off( BYTE(p+25) );
  677.         if( BYTE(p+27) )SND_key_on( BYTE(p+25), BYTE(p+26), BYTE(p+27) );
  678.     }
  679.     if( pcmsw ){        /* pcm */
  680.       if( para[12] ){
  681.         para2[0] = 0x0014; para2[1] = para[12];
  682.         para2[2] = 0x0014; para2[3] = (unsigned int)pbp[para[13]];
  683.         para2[4] = para[14];
  684.         if( pbpsz[para[13]] >= para2[4] )transmit( (char *)para2 );
  685.       }
  686.       if( BYTE(p+28) && pbp[BYTE(p+29)] ){
  687.         if( BYTE(p+28) == 1 ){
  688.         SND_pcm_play_stop( 71 );
  689.         SND_pcm_play( 71, BYTE(p+30), BYTE(p+31), pbp[BYTE(p+29)] );
  690.         }
  691.         if( BYTE(p+28) >= 2 ){
  692.         SND_pcm_play_stop( 71 );
  693.         SND_pcm_play2( 71, BYTE(p+30), BYTE(p+31), pbp[BYTE(p+29)] );
  694.         }
  695.       }
  696.     }
  697.         /* replv = 1~8 level は8まで */
  698.     temp = WORD( p+14 );
  699.     if( temp ){
  700.       if( temp < 0x8000 ){        /* repeat start */
  701.         if( rep[replv][0] != para[0] ){
  702.           replv++;            /* level++ */
  703.           if( replv > 8 )replv = 8;
  704.           rep[replv][0] = para[0];    /* address */
  705.           rep[replv][1] = n - 1;        /* page (-1の調整必要) */
  706.           rep[replv][2] = temp;    /* 回数 */
  707.         }
  708.       }
  709.       else {            /* repeat loop end */
  710.         if( rep[replv][2] ){
  711.           address = rep[replv][0];        /* address 修正 */
  712.           n = rep[replv][1];        /* page NO.修正 */
  713.           rep[replv][2]--;        /* 回数 dec. */
  714.         }
  715.         else {
  716.           replv--;            /* level-- */
  717.           if( replv < 0 )replv = 0;
  718.         }
  719.       }
  720.     }
  721.     n++;
  722.     MOS_rdpos(&sw,&cx,&cy);        /* end check */
  723.     if( sw == 0 )goto mov02;
  724. mov07:    MOS_rdpos(&sw,&cx,&cy);        /* wait loop */
  725.     if( sw & 1 ){
  726.         while( sw == 3 )MOS_rdpos(&sw,&cx,&cy);
  727.         if( sw == 2 )goto mov08;
  728.         while( sw ){
  729.             MOS_rdpos(&sw,&cx,&cy);
  730.             if( sw == 3 )break;
  731.         }
  732.         goto mov02;
  733.     }
  734. mov08:    if( sw )goto mov07;
  735.     SND_pcm_play_stop( 71 );
  736.     for( i=0 ; i<72 ; i++ )SND_key_off( i );
  737.     for( i=0 ; i<8 ; i++ )if( pbp[i] )free( pbp[i] );
  738.     free( bp );
  739.     fclose( fpl );
  740.     return 0;
  741. mov09:    free( bp );
  742. mov10:    fclose( fpl );
  743.     return 58;
  744. }
  745.  
  746. /* fmb & pmb load  return 0:non data return 1:data有り */
  747.  
  748. fmb_pmb_load( namemov )
  749. char *namemov;
  750. {
  751.     FILE *fp;
  752.     int i, j, k, temp;
  753.     char head[256], bank[8];
  754.     char fmbname[13], pmbname[13], path[100];
  755.  
  756.     if( ( fp = fopen( namemov, "rb" ) ) == NULL )return 0;
  757.     temp = fread( head, 1, 256, fp );
  758.     fclose( fp );
  759.     if( temp < 256 )return 0;
  760.     if( DWORD( head + 0 ) != 0x32564f4d )return 0;
  761.     if( DWORD( head + 4 ) != 16 )return 0;
  762.     if( DWORD( head + 16) != 320 )return 0;
  763.     if( DWORD( head + 20) != 240 )return 0;
  764.     for( i=0 ; i<8 ; i++ ){
  765.         fmbname[i] = BYTE( head+40+i );
  766.         if( fmbname[i] == (char)0 )break;
  767.     }
  768.     if( i != 0 ){
  769.         fmbname[i] = '.';
  770.         DWORD( fmbname+i+1 ) = 'F' + 0x100*'M' + 0x10000*'B';
  771.         make_path_name( path, namemov, fmbname );
  772.         SND_fm_bank_load( path, bank );
  773.         for( k=0 ; k<6 ; k++ )SND_inst_change( k, BYTE(head+48+k) );
  774.     }
  775.     for( j=0 ; j<8 ; j++ ){
  776.         pmbname[j] = BYTE( head+56+j );
  777.         if( pmbname[j] == (char)0 )break;
  778.     }
  779.     if( j != 0 ){
  780.         pmbname[j] = '.';
  781.         DWORD( pmbname+j+1 ) = 'P' + 0x100*'M' + 0x10000*'B';
  782.         make_path_name( path, namemov, pmbname );
  783.         SND_pcm_bank_load( path, bank );
  784.         for( k=0 ; k<8 ; k++ )SND_inst_change( 64+k, BYTE(head+64+k) );
  785.     }
  786.     if( i+j )return 1;
  787.     else return 0;
  788. }
  789.  
  790. /* path = fullname(path) + name 合成 */
  791.  
  792. make_path_name( path, fulname, name )
  793. char path[], fulname[], name[];
  794. {
  795.     int i, k;
  796.  
  797.     for( k=0 ; k<80 ; k++ ){
  798.         path[k] = fulname[k];
  799.         if( path[k] == (char)0 )break;
  800.     }
  801.     for( i=k ; i>=0 ; i-- ){    /* path name 抽出 */
  802.         if( path[i] == '\\' || path[i] == ':' )break;
  803.     }
  804.     for( k=0 ; k<13 ; k++ ){
  805.         path[i+1+k] = name[k];
  806.         if( name[k] == (char)0 )break;
  807.     }
  808.     return 0;
  809. }
  810.  
  811. movfile( name, namemov )
  812. char name[], namemov[];
  813. {
  814.     int i;
  815.  
  816.     for( i=0 ; i<76 ; i++ ){
  817.         namemov[i] = name[i];
  818.         if( name[i] == '.' || name[i] == (char)0 )goto mov01;
  819.     }
  820.     return 55;        /* bad file name */
  821. mov01:    if( i == 0 )return 55;
  822.     namemov[i++] = '.'; namemov[i++] = 'M'; namemov[i++] = 'O';
  823.     namemov[i++] = 'V'; namemov[i] = (char)0;
  824.     return 0;
  825. }
  826.  
  827. error_check(number)
  828. int number;
  829. {
  830.     char p[16];
  831.  
  832.     if( number == 0 )return 0;
  833.     MOS_disp(0);
  834.     windget();
  835.     EGB_color(ework,0,E_COLOR);
  836.     gprint( "<<ERROR>>", 0, 471 );
  837.     if( number == 7 )gprint( "out of memory", 88, 471 );
  838.     if( number == 55)gprint( "bad file name", 88, 471 );
  839.     if( number == 58)gprint( "bad data in file", 88, 471 );
  840.     if( number == 1 )gprint( perror( NULL ), 88, 471 );
  841.     if( number == 2 )gprint( perror( NULL ), 88, 471 );
  842.     /*itochar( number, 8, p );
  843.     gprint( p, 0, 471 );*/        /* check for 開発用 */
  844.     gprint( "press mouse button", 352, 471 );
  845.     EGB_color(ework,0,C_COLOR);
  846.     MOS_disp(1);
  847.     mouse(0);
  848.     MOS_disp(0);
  849.     windput();
  850.     return -1;
  851. }
  852.  
  853. void main(ac,av)
  854. char ac,*av[];
  855. {
  856.     char path[80];        /* PATH NAME1 */
  857.     char fullname[100];    /* PATH + FILES NAME1 */
  858.     char namemov[80];    /* mov file name */
  859.  
  860.     char dsp1[] = "<<PLAY>>                                                            FILES    END";
  861.     char dsp2[] = "        WAIT=    MODE=   FILE-NAME<<                                          >>";
  862.     int i, j = 0, wait = 0, mode = 0, temp;
  863.     char dsp[10];
  864.  
  865.     ini();
  866.     if( ac >= 2 ){
  867.         for( i=0 ; i<80 ; i++ ){
  868.             fullname[i] = ( char )( BYTE( av[1] + i ) );
  869.             if( fullname[i] == 0 )break;
  870.         }
  871.         if( ac >= 3 )if( WORD( av[2] ) == '-'+0x100*'v'
  872.                 ||  WORD( av[2] ) == '-'+0x100*'V'
  873.                  )mode = 1;
  874.         goto main_go;
  875.     }
  876. main00:    MOS_disp(0);
  877.     windput();
  878.     windget();
  879.     gprint(dsp1,0,463);
  880.     gprint(dsp2,0,479);
  881.     EGB_color(ework,0,P_COLOR);
  882.     gprint("  PLAY",0,479);        /* PLAY display */
  883.     EGB_color(ework,0,C_COLOR);
  884.     gprint2( fullname, 296, 479 );
  885.     itochar( wait, 2, dsp );
  886.     gprint2( dsp, 104, 479 );
  887.     itochar( mode, 1, dsp );
  888.     gprint2( dsp, 176, 479 );
  889. main01:    MOS_disp(1);
  890.     mouse(1);
  891.     if( (cx >= 56) && (cx < 128) && (cy >=463) ){    /* wait */
  892.         MOS_disp(0);
  893.     main0A:    if( sw == 1 )wait = wait + 1;
  894.         if( sw == 2 )wait = wait - 1;
  895.         if( wait < 0 )wait = 99;
  896.         if( wait > 99 )wait = 0;
  897.         itochar( wait, 2, dsp );
  898.         gprint2( dsp, 104, 479 );
  899.         if( j == 0 ){
  900.             for( i=0 ; i<125000 ; i++ );
  901.             j = 1;
  902.             MOS_rdpos(&sw,&cx,&cy);
  903.             if( sw )goto main0A;
  904.             j = 0;
  905.             goto main01;
  906.         }
  907.         for( i=0 ; i<15000 ; i++ );
  908.         MOS_rdpos(&sw,&cx,&cy);
  909.         if( sw )goto main0A;
  910.         j = 0;
  911.         goto main01;
  912.     }
  913.     if( (cx >= 128) && (cx < 192) && (cy >=463) ){    /* mode */
  914.         MOS_disp(0);
  915.     main0B:    if( sw == 1 )mode = mode + 1;
  916.         if( sw == 2 )mode = mode - 1;
  917.         if( mode < 0 )mode = 1;
  918.         if( mode > 1 )mode = 0;
  919.         itochar( mode, 1, dsp );
  920.         gprint2( dsp, 176, 479 );
  921.         if( j == 0 ){
  922.             for( i=0 ; i<125000 ; i++ );
  923.             j = 1;
  924.             MOS_rdpos(&sw,&cx,&cy);
  925.             if( sw )goto main0B;
  926.             j = 0;
  927.             goto main01;
  928.         }
  929.         for( i=0 ; i<15000 ; i++ );
  930.         MOS_rdpos(&sw,&cx,&cy);
  931.         if( sw )goto main0B;
  932.         j = 0;
  933.         goto main01;
  934.     }
  935.     mouse(0);
  936.     if( (cy < 447) || (sw != 1) )goto main01;
  937.     MOS_disp(0);
  938.     if( cy < 463 ){
  939.         if( cx < 536 )goto main01;
  940.         if( cx < 592 ){                /* files */
  941.             windput();
  942.             filename( path, fullname );
  943.             goto main00;
  944.         }
  945.         if( cx < 608 )goto main01;
  946.         if( cx < 640 ){                /* end */
  947.             windput();
  948.             end();
  949.             return;
  950.         }
  951.         goto main01;
  952.     }
  953.     if( cy < 480 ){
  954.         if( (cx < 56) && (sw == 1) ){        /* play */
  955.             windput();
  956.     main_go:    if( error_check( movfile(fullname,namemov) )==0 ){
  957.             fmb_pmb_load( namemov );
  958.             temp = moving( namemov, wait, mode );
  959.             display_ini();
  960.                 error_check( temp );
  961.             }
  962.             goto main00;
  963.         }
  964.         if( cx < 192 )goto main01;
  965.         if( cx < 640 ){        /* file name */
  966.             windput();
  967.             fileinput( fullname );
  968.             goto main00;
  969.         }
  970.         goto main01;
  971.     }
  972.     goto main01;
  973. }
  974.